﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Web;
using LM_Shop.Models.Auctions;

namespace LM_Shop.Services.Auction
{
    [Export(typeof(IAuctionService))]
    public class AuctionServiceDesign : IAuctionService
    {
        private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

        private readonly IEnumerable<AuctionModel> auctionList = generateList();

        public AuctionModel GetDetails(int id)
        {
            logger.Trace("getdetails");
            var result = auctionList.FirstOrDefault(x => x.Id == id);
            return result;
        }

        public IEnumerable<AuctionModel> GetAuctionList()
        {

            return auctionList;

        }

        private static IEnumerable<AuctionModel> generateList()
        {
            var auctionModel = new AuctionModel();
            auctionModel.Id = 1;
            auctionModel.Price = 1233.123;
            auctionModel.Title = "tytul sialalala";
            auctionModel.Count = 10;

            var auctionModel2 = new AuctionModel();
            auctionModel2.Id = 2;
            auctionModel2.Price = 54.123;
            auctionModel2.Title = "Plecak";
            auctionModel2.Count = 14;

            var auctionModel3 = new AuctionModel();
            auctionModel3.Id = 3;
            auctionModel3.Price = 765;
            auctionModel3.Title = "Kubek";
            auctionModel3.Count = 6;

            return new List<AuctionModel> { auctionModel, auctionModel2, auctionModel3 };
        }


        public void Buy(int id)
        {
            var model = auctionList.FirstOrDefault(p => p.Id == id);
            if (model != null)
                model.Count--;

        }
    }
}